package com.didispace;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@EnableDiscoveryClient
@SpringBootApplication
//@EnableCircuitBreaker
@RestController
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class,args);
	}
	@RequestMapping(value = "/first", method = RequestMethod.GET)  
    public Map<String, Object> firstResp (HttpServletRequest request){  
        Map<String, Object> map = new HashMap<String, Object>(); 
//        request.getSession().setAttribute("request Url", request.getRequestURL());  
        map.put("request Url", request.getSession().getAttribute("springboot"));  
        map.put("session", request.getSession().getId());
        return map;  
    }  
	
	 @RequestMapping(value = "/sessions", method = RequestMethod.GET)  
	    public Object sessions (HttpServletRequest request){  
		 System.err.println("++++++++++++++++++");
		  Object o = request.getSession().getAttribute("springboot");  
	        if(o == null){  
	            o = "spring boot 牛逼了!!!有端口"+request.getLocalPort()+"生成";  
	            request.getSession().setAttribute("springboot", o);  
	        }  
	          
	        return "端口=" + request.getLocalPort() +  " sessionId=" + request.getSession().getId() +"<br/>"+o;  
	    }  
}
